  <script type="text/javascript"><!--//--><![CDATA[//><!--

var LOVCalonPenyewa = function(ao_option){
    try{
        if(ao_option==undefined){ ao_option={}; }
        var lf_onSelect = (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
        
        // Create Popup
        var $popup  = openPopup({ title:'Daftar Tempat' , width:700, height:370 });
        var ls_id   = $popup.attr('id');
        
        // Append Datagrid Container
        var ls_gridName = 'grid_'+ls_id;
        $popup  .html(  $('<div>')  .attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
                                    .html(  $('<div>').html($('<form>') .attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
                                                                        .html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
                                                            )
                                            )
                        )
                .append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
        
        $('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
        $('#btn_search'+ls_id).linkbutton({  
            plain:true  
        }); 
        
        // Build Datagrid
        var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
        $('#'+ls_gridName).datagrid({  
            url:gs_path+'/pro_sewa_gedung/getdataLOV/'+ls_param,
            queryParams: $('#fm_search_'+ls_id).serializeObject(),
            height:337,
            pagination:true,
            singleSelect:true,
            columns:[[
                { field : 'id_tempat', title : 'ID Tempat', width : 170, sortable:true },
                { field : 'lokasi_tempat', title : 'Lokasi Tempat', width : 150, sortable:true },
                { field : 'no_toko', title : 'No Toko', width : 80, sortable:true },
                { field : 'harga_sewa', title : 'Harga sewa', width : 150, sortable:true },
                { field : 'luas_tempat', title : 'Luas Tempat', width : 150, sortable:true },
                { field : 'id_sewa', title : 'ID Sewa', width : 150, sortable:true },
                { field : 'id_lokasi', title : 'ID Lokasi', width : 150, sortable:true },
            ]],
            onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
        });
        
    } catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};


    $(document).ready(function() {

        /*var kode_tenant_auto = '<?php echo $kode_tenant_auto ; ?>'*/

        // Setup Form
        $('#form_master').setupForm([
            { name: 'no_tenant', type: 'text', size: 'short', readonly:true , maxlength: 10, },
            { name: 'nama_tenant', type: 'text', size: 'long', maxlength: 200, noempty:true },
            { name: 'alamat_lengkap', type: 'text', size: 'long', maxlength: 255, noempty:true },
            { name: 'jenis_usaha', type: 'text', size: 'medium', maxlength: 255, noempty:true },
            { name: 'no_telephone', type: 'text', size: 'medium', maxlength: 20 },
            { name: 'no_handphone', type: 'text', size: 'medium', maxlength: 20 },
            { name: 'lokasi_tempat', type: 'lov', size: 'medium',
                onClearButton:function(){
                    $(this).setval(''); 
                    $('#lokasi_tempat').setval('');
                    $('#id_sewa').setval(''); 
                    $('#no_toko').setval('');
                    $('#harga_sewa').setval('');
                    $('#id_lokasi').setval('');
                    $('#luas_tempat').setval('');

                },
                onActionButton:function(){ 
                    LOVCalonPenyewa({ onSelect:function(row){ 
                        $('#lokasi_tempat').setval(row.lokasi_tempat); 
                        $('#id_sewa').setval(row.id_sewa); 
                        $('#id_lokasi').setval(row.id_lokasi); 
                        $('#no_toko').setval(row.no_toko);
                        $('#harga_sewa').setval(row.harga_sewa);
                        $('#luas_tempat').setval(row.luas_tempat);
                    } }); 
                }
            },
            { name: 'no_toko', type: 'text', size: 'short', maxlength: 10, readonly:true },
            { name: 'luas_tempat', type: 'text', size: 'short', maxlength: 10, readonly:true },
            { name: 'status_anggota', type: 'text', size: 'medium', maxlength: 255 },
            { name: 'no_anggota', type: 'text', size: 'medium', maxlength: 20 },
            { name: 'no_id_card', type: 'text', size: 'medium', maxlength: 20 },
            { name: 'status_tenant', type: 'text', size: 'medium', maxlength: 255 },
            { name: 'no_kontrak', type: 'text', size: 'medium', maxlength: 40 },
            { name: 'periode_awal_sewa', type: 'date', size: 'medium', maxlength: 20 },
            { name: 'periode_akhir_sewa', type: 'date', size: 'medium', maxlength: 20 },
            { name: 'jangka_waktu', type: 'text', size: 'medium', maxlength: 20 },
            { name: 'harga_sewa', type: 'text', size: 'medium', readonly:true},
            { name: 'keterangan', type: 'text', size: 'medium', maxlength: 255},
        ], <?php echo json_encode($data); ?>);
        
               
        $("#anggota-hide").hide();
        $("#anggota-hide2").hide();
        $("#pertokoan_belakang").hide();
        $("#tenant-hide").hide();
        $("#tenant-hide2").hide();
        $("#tenant-hide3").hide();
        $("#tenant-hide4").hide();
        $("#tenant-hide5").hide();
        $("#tenant-hide6").hide();

        <?php if($mode=="create"){ ?>
        var kode_tenant_auto = "<?php echo $kode_tenant_auto; ?>";
        //alert(id_lokasi);
        $('#no_tenant').setval(kode_tenant_auto);
        <?php } ?>

        <?php if($mode=="edit"){ ?>
        var id_lokasi_edit = '<?php echo $id_lokasi_edit; ?>';
        var id_sewa_edit = '<?php echo $id_sewa_edit; ?>';
        //alert(id_lokasi);
        $('#no_tenant').readonly();
        $('#id_lokasi').setval(id_lokasi_edit);
        $('#id_sewa').setval(id_sewa_edit);
        <?php } ?>
        
        // Set Action Button
        var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
                            $('#form_master').submitForm(   '/'+controller+'/ajax_post', { onComplete : function(){ loadPage('/'+controller+'/Index') } }); 
                        }},
                       { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
        setAction(buttons);

        
        $("#status_anggota").change(function() {
             var str = "";
             $("#status_anggota option:selected").each(function() {
                str = $(this).text();
             });

             if(str == 'Anggota'){
                $("#anggota-hide").show();
                $("#anggota-hide2").show();
                $("#pertokoan_belakang").show();
             }
             else if(str == 'Bukan Anggota'){
                $("#anggota-hide").hide();
                $("#anggota-hide2").hide();
                $("#pertokoan_belakang").hide();
             }
             
        });

        $("#status_tenant").change(function() {
             var str = "";
             $("#status_tenant option:selected").each(function() {
                str = $(this).text();
             });

             if(str == 'Tenant'){
                $("#tenant-hide").show();
                $("#tenant-hide2").show();
                $("#tenant-hide3").show();
                $("#tenant-hide4").show();
                $("#tenant-hide5").show();
                $("#tenant-hide6").show();
             }
             else if(str == 'Calon Penyewa'){
                $("#tenant-hide").hide();
                $("#tenant-hide2").hide();
                $("#tenant-hide3").hide();
                $("#tenant-hide4").hide();
                $("#tenant-hide5").hide();
                $("#tenant-hide6").hide();
             }
             
        });

        // Create Tab
        $('#tt').tabs({ border:false });  
        
        // Focus at First Object
        $('#form_master').focusFirst();

    });




//--><!]]></script>

<div id="form_master_message" style="display:none;"></div>
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td><input id="id_lokasi" name="id_lokasi" type="hidden" />
            <input id="id_sewa" name="id_sewa" type="hidden" />
        </td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Tenant</td>
        <td><input id="no_tenant" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Tenant</td>
        <td><input id="nama_tenant" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Jenis Usaha</td>
        <td><input id="jenis_usaha" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Alamat Rumah/Kantor</td>
        <td><textarea id="alamat_lengkap" name="alamat_lengkap" rows="5" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Telephone</td>
        <td><input id="no_telephone" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Handphone</td>
        <td><input id="no_handphone" /></td>
    </tr> 
    <tr>
        <td class="label" style="width:150px">Lokasi Tempat</td>
        <td><input id="lokasi_tempat" name="lokasi_tempat">
        </td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Toko</td>
        <td><input id="no_toko" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Luas Tempat</td>
        <td><input id="luas_tempat" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Status Anggota</td>
        <td>
            <select id="status_anggota" name="status_anggota">
                <option value="null">(Pilih Status)</option>
                <option value="Bukan Anggota">Bukan Anggota</option>
                <option value="Anggota">Anggota</option>
            </select>
        </td>
    </tr>
    <tr id="anggota-hide">
        <td class="label" style="width:150px">No Anggota</td>
        <td><input id="no_anggota" /></td>
    </tr>
    <tr id="anggota-hide2">
        <td class="label" style="width:150px">No ID Card</td>
        <td><input id="no_id_card" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Status Tenant</td>
        <td>
            <select id="status_tenant" name="status_tenant">
                <option value="null">(Pilih Status)</option>
                <option value="Calon Tenant">Calon Tenant</option>
                <option value="Tenant">Tenant</option>
            </select>
        </td>
    </tr>
    <tr id="tenant-hide">
        <td class="label" style="width:150px">No Kontrak</td>
        <td><input id="no_kontrak" /></td>
    </tr>
    <tr id="tenant-hide2">
        <td class="label" style="width:150px">Periode Awal Sewa</td>
        <td><input id="periode_awal_sewa" /></td>
    </tr>
    <tr id="tenant-hide3">
        <td class="label" style="width:150px">Periode Akhir Sewa</td>
        <td><input id="periode_akhir_sewa" /></td>
    </tr>
    <tr id="tenant-hide4">
        <td class="label" style="width:150px">Jangka Waktu</td>
        <td><input id="jangka_waktu" /></td>
    </tr>
    <tr id="tenant-hide5">
        <td class="label" style="width:150px">Harga Sewa</td>
        <td><input id="harga_sewa" /></td>
    </tr>
    <tr id="tenant-hide6">
        <td class="label" style="width:150px">Keterangan</td>
        <td><textarea id="keterangan" name="keterangan" /></td>
    </tr>  
</table>
